package com.travelms.service.adminuserpage;

import com.travelms.dao.DBFind;
import com.travelms.pojo.User;

import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Scanner;

public class DeleteUser {
    public DeleteUser() throws SQLException, IOException {
        Scanner sc = new Scanner(System.in);
        DBFind dbFind = new DBFind();
        System.out.println("当前已有用户列表如下,:");
        ArrayList<User> allUser = dbFind.getAllUser();
        for (User user : allUser) {
            System.out.println(user);
        }
        while (true) {
            System.out.println("请输入你要删除的用户");
            String dele = sc.nextLine();
            if(dele.isEmpty()){
                System.out.println("输入错误");
                continue;
            }

            if (dbFind.deleteUser(dele)){
                System.out.println("删除成功");
                System.out.println("删除后的信息如下");

                allUser = dbFind.getAllUser();
                for (User user : allUser) {
                    System.out.println(user);
                }
                System.out.println("按任意键退出");
                String q = sc.nextLine();
                break;
            }else {
                System.out.println("删除失败");
                break;
            }
        }

    }
}
